<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 分享记录
 */
namespace app\allwin\model;
use think\Model;
use think\helper\Time;
use filter\Filter;

class AllwinInfoShare extends Model{

    protected $pk     = 'id';

     /**
     * 判断分享记录如果合规发红包
     * @return void
     */
    public function redRocket(array $param,$ucode = null){
        if(empty($ucode)){
            return;
        }
        if ($param['is_pay'] <= 0 || $param['task_money'] <= 0) {
            return;
        }
        $uid = model('SystemUser')->isInvite(Filter::filter_escape($ucode));
        if(empty($uid)){
            return;
        }
        list($start,$end) = Time::today();
        $condition[] = ['info_id','=',$param['id']];
        $condition[] = ['times','>',$start];
        $condition[] = ['uid','=',$uid];
        $rel = self::where($condition)->find();
        if($rel){
            return self::where(['info_id'=> $param['id']])->setInc('views',1);
        }else{
            $data['uid']     = $uid;
            $data['info_id'] = $param['id'];
            $data['views']   = 1;
            $data['times']   = time();
            return self::insert($data);
        }
    }
     /**
     * 发红包
     * @return void
     */
    public function postRedRocket(array $param,$ucode = null){
        
    }
}